package com.sailorj.itools.constants;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@State(name = "dhg-patch",storages = {
        @Storage(value = "dhgPatch.xml")
})
public class MyState implements PersistentStateComponent<MyState> {

    private StorageConfig config;

    public static MyState getInstance(){
        return ServiceManager.getService(MyState.class);
    }

    @Nullable
    @Override
    public MyState getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull MyState myState) {
        if (null == myState) {
            return;
        }
        XmlSerializerUtil.copyBean(myState, this);
    }

    public StorageConfig getConfig() {
        if (null == config) {
            config = new StorageConfig();
        }
        return config;
    }

    public void setConfig(StorageConfig config) {
        this.config = config;
    }
}
